package com.finger.forest.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.finger.forest.HotCheckActivity;
import com.finger.forest.R;
import com.finger.forest.model.FzHotspot;
import com.finger.forest.model.GpsEquipmentModel;
import com.finger.forest.utils.ToastUtils;

import java.util.List;


public class GPSAdapter extends BaseAdapter{
    private  Context context;
    private List<GpsEquipmentModel> mList;//数据源
    private LayoutInflater mInflater;//布局装载器对象

    // 通过构造方法将数据源与数据适配器关联起来
    // context:要使用当前的Adapter的界面对象
    public GPSAdapter(Context context, List<GpsEquipmentModel> list) {
        this.context = context;
        this.mList = list;
        this.mInflater = LayoutInflater.from(context);
    }

    @Override
    //ListView需要显示的数据数量
    public int getCount() {
        return mList.size();
    }

    @Override
    //指定的索引对应的数据项
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    //指定的索引对应的数据项ID
    public long getItemId(int position) {
        return position;
    }

    @Override
    //返回每一项的显示内容
    public View getView(int position, View convertView, ViewGroup parent) {
        //将布局文件转化为View对象
        View view = mInflater.inflate(R.layout.item_gps,null);

        /**
         * 找到item布局文件中对应的控件
         */
        TextView gpsName = (TextView) view.findViewById(R.id.tv_gps_name);
        TextView gpsCode = (TextView) view.findViewById(R.id.tv_gps_code);
        TextView gpsStatus = (TextView) view.findViewById(R.id.tv_gps_status);
        Button detailBtn = (Button) view.findViewById(R.id.detailBtn);

        //获取相应索引的ItemBean对象
        GpsEquipmentModel bean = mList.get(position);

        /**
         * 设置控件的对应属性值
         */
        gpsName.setText(bean.getTerminalName());
        gpsCode.setText(bean.getTerminalId());
        gpsStatus.setText(bean.getTerminalType());

        detailBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtils.show("查看"+bean.getId());
            }
        });

        return view;
    }
}